package com.danco.training.zaneuskaya.faces;

import java.io.Serializable;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.danco.training.zaneuskaya.domain.City;
import com.danco.training.zaneuskaya.domain.Country;
import com.danco.training.zaneuskaya.service.CityService;
import com.danco.training.zaneuskaya.service.CountryService;

/**
 * @author Zaneuskaya Aliaksandra
 *
 */
@Component
@Scope("request")
public class LocationBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final Logger LOGGER = Logger.getLogger(LocationBean.class);

	@Autowired
	private CityService cityService;

	private Country currentCountry;

	private City currentCity;

	@Autowired
	private CountryService countryService;

	private List<City> cityList;

	private List<Country> countryList;

	private int countryId;

	private int cityId;

	public int getCityId() {
		return cityId;
	}

	public void setCityId(int cityId) {
		this.cityId = cityId;
	}

	public int getCountryId() {
		return countryId;
	}

	public void setCountryId(int countryId) {
		this.countryId = countryId;
	}

	public CountryService getCountryService() {
		return countryService;
	}

	public void setCountryService(CountryService countryService) {
		this.countryService = countryService;
	}

	public List<Country> getCountryList() {
		countryList = countryService.getEntityList();
		LOGGER.info("Get countryList");
		return countryList;
	}

	public void setCountryList(List<Country> countryList) {

		this.countryList = countryList;
	}

	public CityService getCityService() {
		return cityService;
	}

	public void setCityService(CityService cityService) {
		this.cityService = cityService;
	}

	public List<City> getCityList() {
		cityList = cityService.getCityByCountry(currentCountry);
		LOGGER.info("Get cityList");
		return cityList;
	}

	public void setCityList(List<City> cityList) {

		this.cityList = cityList;
	}

	public Country getCurrentCountry() {

		return countryService.getEntityById(countryId);
	}

	public void setCurrentCountry(Country currentCountry) {

		this.currentCountry = currentCountry;
	}

	public City getCurrentCity() {

		return currentCity;
	}

	public void setCurrentCity(City currentCity) {

		this.currentCity = currentCity;
	}

}
